package com.unlcn.ils.erpInterfaces.service.buss.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.unlcn.ils.erpInterfaces.dao.mapper.SmgetpointMapper;
import com.unlcn.ils.erpInterfaces.dao.model.Smgetpoint;
import com.unlcn.ils.erpInterfaces.service.buss.ISmgetpointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * Created by lenovo on 2018/6/11.
 */
@Service
public class SmgetpointServiceImpl implements ISmgetpointService {

    @Autowired
    private SmgetpointMapper smgetpointMapper;

    @Override
    public Long getPointId(Long customerId, String pointName, String province) {

        // 检查提车库是否存在
        Wrapper<Smgetpoint> ew  = new EntityWrapper<Smgetpoint>();
        ew.eq("ICUSTOMERID", customerId);
        ew.eq("VCPOINTNAME", pointName);
        ew.eq("BACTIVE", 1);
        List<Smgetpoint> smgetpointList = smgetpointMapper.selectList(ew);

        if (CollectionUtils.isEmpty(smgetpointList)) {

            Long ilineid = smgetpointMapper.getNextIlineid();
            Smgetpoint smgetpoint = new Smgetpoint();
            smgetpoint.setIlineid(ilineid);
            smgetpoint.setIcustomerid((double) customerId);
            smgetpoint.setIcontractid((double) 10);
            smgetpoint.setIwarehouseid((double) 10);
            smgetpoint.setVcpointname(pointName);
            smgetpoint.setVccityname(pointName);
            smgetpoint.setVcprovince(province);
            smgetpoint.setVcmemo("用于wms体系调度");
            smgetpoint.setVccontact("wms");
            smgetpoint.setBactive((double)1);
            smgetpointMapper.insert(smgetpoint);

            return ilineid;
        } else {
            return smgetpointList.get(0).getIlineid();
        }
    }
}
